<template>
  <div class="pad_10">
    <el-form ref="queryRef" :inline="true" label-width="68px">
      <el-form-item>
        <el-button @click="handleQuery">保存</el-button>
        <el-button @click="Cancel">取消</el-button>
        <!-- <el-button :disabled="!route.query.id" @click="auditFun">审核</el-button> -->
      </el-form-item>
    </el-form>
    <el-divider />
    <SetUserSelect
      :key="keys"
      ref="setUserSelect"
      class="queryForm"
      :labelwidth="100"
      :isShowUserBtn="false"
      :buttonIsShow="false"
      :formData="bill"
      :queryParams="datas"
      @selChangeFun="changeFun"
    ></SetUserSelect>
    <el-form ref="queryFormmin" :model="datas" label-width="75px">
      <el-card class="box-card" shadow="never">
        <template #header>
          <div class="card-header">
            <span>上传资料</span>
          </div>
        </template>
        
        <el-row :gutter="20" align="stretch">
          <el-col :span="12">
            <el-form-item label-width="85px" label="资料:" 
            prop="url" 
            :rules="[
            {
              required: true,
              message: '请上传资料',
              trigger: ['blur'],
            },
          ]">
            <file-upload
              :isShowTip="false"
              showTipText=""
              :limit="1"
              v-model="datas.url"
            ></file-upload>
          </el-form-item>
          </el-col>
        </el-row>
      </el-card>
   </el-form>
  </div>
</template>
<script setup lang="ts">
import { useStore } from "vuex";
import { ref, getCurrentInstance, watch, computed } from "vue";
import { addresource, resourceId, eitHresource  } from "@/api/missionInforma";
import data from "./data";
import { useRoute } from "vue-router";
const { bill, datas } = data;
datas.value = {
  status: '1'
}
const { proxy } = getCurrentInstance();
let proxys: any = proxy;
const route: any = useRoute();
let keys = ref<any>("");
const { data_manag_status } = proxys.useDict(
  "data_manag_status"
);
// watch(data_manag_type, (newV, oldV) => {
//   bill.value[3].selectData = data_manag_type;
//   keys.value = new Date().getTime();
// });

watch(data_manag_status, (newV, oldV) => {
  bill.value[4].selectData = data_manag_status;
  keys.value = new Date().getTime();
});
let store = useStore()
const cachedViews:any = computed(() => {
    return store.state.user.agency
})

// 
datas.value.uploadUserName = cachedViews.value.agencyName
datas.value.uploadUserId = cachedViews.value.agencyId
route.query.id &&
  resourceId(route.query.id).then((res) => {
    res.data.status = "" + res.data.status;
    res.data.type = "" + res.data.type;
    res.data.setTime = res.data.uploadTime
    datas.value = res.data;
    datas.value.uploadUserId = cachedViews.value.agencyId
    datas.value.uploadUserName = cachedViews.value.agencyName
  });
const handleQuery = function (): void {
  Promise.all([proxys.$refs.setUserSelect.submitForm(),proxys.$refs.queryFormmin.validate()]).then((valid) => {
    (!route.query.id ? addresource : eitHresource)(valid[0]).then(() => {
      proxys.$modal.msgSuccess(`${route.query.id ? "修改" : "新增"}成功`);
      Cancel();
    });
  })
};

const changeFun = function (e: any): void {
  console.log(e);
};
const Cancel = () => {
  datas.value = {};
  const obj = { path: "/material/missionInformaList" };
  proxys.$tab.closeOpenPage(obj);
};
</script>
<style scoped>
.pad_10 {
  padding: 10px;
}
.pad_10 .el-form--inline .el-form-item {
  margin: 0;
}
.el-divider--horizontal {
  margin: 10px 0;
}
</style>